//
// Created by dukang wang on 2025/1/4.
//

#ifndef HYAUDIO_AUDIOPLAYER_H
#define HYAUDIO_AUDIOPLAYER_H

#include "../AndroidLog.h"
#include "DataQueue.h"
#include "pthread.h"
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
#include <time.h>

namespace hy {

    class AudioPlayer {

    public:
        DataQueue *dataQueue;
        int sample_rate = 0;
        pthread_t play_thread_t;

        SLAndroidSimpleBufferQueueItf pcmBufferQueue = NULL;
        SLObjectItf engineObject = NULL;
        SLEngineItf engineEngine = NULL;
        SLObjectItf pcmPlayerObject = NULL;
        SLObjectItf outputMixObject = NULL;
        SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;
        SLPlayItf pcmPlayerPlay = NULL;
        SLMuteSoloItf pcmMutePlay = NULL;
        SLVolumeItf pcmVolumePlay = NULL;

    public:
        AudioPlayer();

        ~AudioPlayer();

        int Init(int sample_rate);

        void play();

        void putPcmData(PcmData *pcmData, int size);

        int getPcmDataSize();

        int getCurrentSampleRateForOpensles(int sample_rate);

        void stop();

        void resume();

        void pause();

        void release();


    };

} // hy

#endif //HYAUDIO_AUDIOPLAYER_H
